<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/8/1
 * Time: 11:43
 */

namespace app\api\controller;

use app\api\model\Collection as M;

class Collection extends Base
{

    public function indexpoi(){
        $openId= request()->post('openid');
        $goods_id=input('goods_id');
        $collection_types=input('collection_types');
        $m=new M();
        $member= db('member')->where('program_openid',$openId)->find();
        $map['member_id']=$member['member_id'];
        $map['goods_id']=$goods_id;
        $map['collection_types']=$collection_types;
        $cl= db('collection')->where($map)->find();
        $shu=[];
        if (!empty($cl)){
            $res = db('collection')->where('collection_id',$cl['collection_id'])->delete();
            if ($res==true){
                $shu=['code'=>0,'msg'=>'取消收藏成功'];
            }else{
                $shu=['code'=>-1,'msg'=>'取消收藏失败'];
            }
        }else{
            $res= db('collection')->insert([
                'goods_id'=>$goods_id,
                'member_id'=>$member['member_id'],
                'collection_types'=>(int)$collection_types,
                'creattime'=>time()
            ]);
            if ($res==true){
                $shu=['code'=>0,'msg'=>'收藏成功'];
            }else{
                $shu=['code'=>-1,'msg'=>'收藏失败'];
            }
        }
        return json_encode($shu);
    }





}